package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.BaseContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.domian.Orders;
import com.itheima.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 何须浅碧深红色
 * @date 2022/9/18
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        ordersService.submit(orders);
        return R.success("下单成功");
    }
    @GetMapping("/userPage")
    public R<Page> page(int page,int pageSize){
        Long currentId = BaseContext.getCurrentId();
        Page<Orders> pageInfo = new Page<>(page,pageSize);
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Orders::getUserId,currentId);
        wrapper.orderByAsc(Orders::getOrderTime);
        ordersService.page(pageInfo,wrapper);
        return R.success(pageInfo);
    }
    @GetMapping("/page")
    public R<Page> pageinfo(int page,int pageSize,String name){
////        Long currentId = BaseContext.getCurrentId();
//        Page<Orders> pageInfo = new Page<>(page,pageSize);
//        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
////        wrapper.eq(Orders::getUserId,currentId);
//        wrapper.orderByAsc(Orders::getOrderTime);
//        ordersService.page(pageInfo,wrapper);
      return ordersService.selectAll(page,pageSize,name);
//        return R.success(pageInfo);
    }
}
